#  Copyright (C) 2010 Luca Piccinelli
# 
#  This program is free software: you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation, either version 3 of the License, or
#  (at your option) any later version.
#  
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#  
#  You should have received a copy of the GNU General Public License
#  along with this program.  If not, see <http://www.gnu.org/licenses/>.

'''
Created on Jun 18, 2011

@author: picci
'''

from pypelab.common.patterns import Borg

class IdGenerator(Borg):
    def __init__(self, start_id = 0):
        if 'last_id' not in self.__dict__:
            self.last_id = start_id
            
    def generate(self):
        self.last_id += 1
        return str(self.last_id)
    
    def registerID(self, id):
        if int(id) > self.last_id: self.last_id = int(id)